package chaowan.Service.impl;

import chaowan.Mapper.OrderDetailMapper;
import chaowan.Service.OrderDetailService;
import chaowan.pojo.OrderDetail;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderDetailServiceImpl implements OrderDetailService {

    @Resource
    private OrderDetailMapper orderDetailMapper;

    @Override
    public List<OrderDetail> getAllDetails() {
        return orderDetailMapper.selectAll();
    }

    @Override
    public OrderDetail getDetailById(Long detailId) {
        return orderDetailMapper.selectById(detailId);
    }

    @Override
    public int save(OrderDetail orderDetail) {
        return orderDetailMapper.insert(orderDetail);
    }

    @Override
    public int update(OrderDetail orderDetail) {
        return orderDetailMapper.update(orderDetail);
    }

    @Override
    public int deleteById(Long detailId) {
        return orderDetailMapper.deleteById(detailId);
    }

    @Override
    public List<OrderDetail> getDetailsByOrderId(Long orderId) {
        return orderDetailMapper.findByOrderId(orderId);
    }
    @Override
    public List<OrderDetail> getDetailsByOrderId(Long orderId, int page, int size) {
        int offset = (page - 1) * size;
        return orderDetailMapper.selectByOrderIdWithPagination(orderId, offset, size);
    }

    @Override
    public int getTotalCountByOrderId(Long orderId) {
        return orderDetailMapper.countByOrderId(orderId);
    }
}